#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckTimeLineRange(CheckBase):
    def __init__(self):
        super(CheckTimeLineRange, self).__init__()
        pass

    def check(self):

        ast = cmds.playbackOptions(q=True, ast=True)
        mint = cmds.playbackOptions(q=True, min=True)

        aet = cmds.playbackOptions(q=True, aet=True)
        maxt = cmds.playbackOptions(q=True, max=True)
        result_log = 'Warning:'
        if ast != mint:
            result_log += u'<br>时间线起始帧不一致,min:{} astL:{}'.format(mint, ast)
        if aet != maxt:
            result_log += u'<br>时间线结束帧不一致,max:{} aet:{}'.format(maxt, aet)
        if ast < 1001:
            result_log += u'<br><font color=\"#FF0000\">时间线起始帧小于项目起始帧(1001)</font>'

        if ast == mint and aet == maxt and ast > 1000:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        ast = cmds.playbackOptions(q=True, ast=True)
        mint = cmds.playbackOptions(q=True, min=True)

        aet = cmds.playbackOptions(q=True, aet=True)
        maxt = cmds.playbackOptions(q=True, max=True)

        if ast != mint:
            cmds.playbackOptions(e=True, ast=mint)
        if aet != maxt:
            cmds.playbackOptions(e=True, aet=maxt)
        return self.check()